/********************************************************************
Name: Table A3: Distributions of Outcomes for Sheriffs
Author: Dan Thompson
Date: August 2019
Notes:
********************************************************************/

* Set the working directory 
gl root = "$sanctuary_root"
gl root = "YOUR_WORKING_DIRECTORY"

* Prepare the analysis data
use "$root/data/panel of outcomes.dta", clear
gen year = policy_year - 1
merge 1:1 state county year ///
	using "$root/data/manifest summaries and election timing - long.dta", keep(1 3) nogen
keep if no_sheriff==0 & partisan==1
merge 1:1 state county policy_year using "$root/data/elections in rd.dta", keep(1 3) nogen
gen requests_per1k = 1000*all_sheriff/pop2000
gen detentions_per1k = 1000*detained_sheriff/pop2000
gen arrests_per1k_2018 = 1000*arrests/pop2000
gen _287g = 1 - no_287g
gen contract_detention = 1 - no_detention_contract
gen ice_alerts = 1 - no_ice_alerts

* Row 1
sum share_detained_sheriff if inrange(policy_year, 2006, 2015)
sum share_detained_sheriff if in_rd==1 & inrange(policy_year, 2006, 2015)

* Row 2
sum detentions_per1k if inrange(policy_year, 2006, 2015)
sum detentions_per1k if in_rd==1 & inrange(policy_year, 2006, 2015)

* Row 3
sum requests_per1k if inrange(policy_year, 2006, 2015)
sum requests_per1k if in_rd==1 & inrange(policy_year, 2006, 2015)

* Row 4
sum _287g if inrange(policy_year, 2006, 2015)
sum _287g if in_rd==1 & inrange(policy_year, 2006, 2015)

* Row 5
sum contract if inrange(policy_year, 2006, 2015)
sum contract if in_rd==1 & inrange(policy_year, 2006, 2015)

* Row 6
sum ice_interrogation if inrange(policy_year, 2006, 2015)
sum ice_interrogation if in_rd==1 & inrange(policy_year, 2006, 2015)

* Row 7
sum ice_alerts if inrange(policy_year, 2006, 2015)
sum ice_alerts if in_rd==1 & inrange(policy_year, 2006, 2015)

* Row 8
sum arrests_per1k_2018 if inrange(policy_year, 2017, 2018)
sum arrests_per1k_2018 if in_rd==1 & inrange(policy_year, 2017, 2018)

* Row 9
sum enforcement_scale_2018 if inrange(policy_year, 2017, 2018)
sum enforcement_scale_2018 if in_rd==1 & inrange(policy_year, 2017, 2018)

* Row 10
sum in_287g_2018 if inrange(policy_year, 2017, 2018)
sum in_287g_2018 if in_rd==1 & inrange(policy_year, 2017, 2018)

* Row  11
sum sanctuary_2018 if inrange(policy_year, 2017, 2018)
sum sanctuary_2018 if in_rd==1 & inrange(policy_year, 2017, 2018)

